package org.example.service.assign;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.example.entity.OrderVO;
import org.example.service.complex.ComplexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Slf4j
@Service
public class AssignServiceImpl implements AssignService {

    // 复杂工作流的进程ID
    private final static String ProcessInstanceByKey = "demoProcess2";

    @Autowired
    RuntimeService runtimeService;

    @Autowired
    TaskService taskService;

    @Autowired
    HistoryService historyService;

    @Override
    public String startProcessAssign(String userName, String userNames) {
        Map<String, Object> map = new HashMap<>(16);
        map.put("username", userName);
        map.put("usernames", userNames);
        // 启动一个流程(动态分配任务Assignee)
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(ProcessInstanceByKey, map);
        log.info("动态分配任务======={}", processInstance.getId());
        return processInstance.getId() + " Assign success";
    }

    @Override
    public String claimTask(String taskId, String userName) {
        // claim认领任务
        taskService.claim(taskId, userName);
        return userName + " 认领任务 success";
    }
}
